<?php
  
class Auth_Model
{
    
private static $_instance = null ;
private $user ;
private $id ;
private $isReg ;
private $isAdmin ;
private $session = array() ;


    private function __construct() {
        $this->sesStart();
        $this->setAuth();
    }
    
    private function __clone() {}
    
    /**
    * Метод для вызова данного класса как singletone
    * 
    */
    public static function getInstance()
    {
        if( null == self::$_instance) { 
            self::$_instance = new Auth_Model();
        }
        return self::$_instance;
    }

    public function getCurrentUser()
    {
        return $this->user;
    }
    
    public function getIsReg()
    {
        return $this->isReg;
    }
    
    public function getIsAdmin()
    {
        return $this->isAdmin;
    }
    
    public function getId()
    {
        return $this->id;
    }
    
    
    //public function isAuthorOfPost(){}    
    //public function isUserWithEmail(){}
    
    /**
    * запустить сессию
    */
    public function sesStart () 
    {
        if (!isset($_SESSION)) {
        session_set_cookie_params(10800);
        session_start();
        }
        $this->session = $_SESSION;
    }
    
    /**
    * Удалить сессию
    */
    public function sesDestroy ()
    {
        if (isset($_SESSION)) {
            session_destroy();
        }
    }

    
    public function setAuth()
    {
        if (isset( $this->session['name'])) {
            $this->user     = $this->session['name'];
            $this->id       = $this->session['id'];
            $this->isAdmin  = $this->session['isAdmin'];
            $this->isReg    = true;
        } else {
            $this->isReg    = false;              
        }
    }
    
    public function getUserId()
    {
        return $this->id;
    }
 
}